<?php
class Boss_Api {

    const URI = 'http://boss.yahooapis.com';
    
    protected $_appId;
    
    public function __construct($appId) {
    
        $this->setAppId($appId);
    
    }
    
    public function setAppId($appId) {
    
        $this->_appId = $appId;
        return $this;
    
    }
    
    public function getAppId() {
    
        return $this->_appId;
    
    }
    
    public function dispatch(Boss_Request $request) {
    
        $request->setParam('appId', $this->getAppId());
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, self::URI . $request->getUri());
        curl_setopt($ch, CURLOPT_CRLF, true); // convert newlines to CRLF
        curl_setopt($ch, CURLOPT_HEADER, 1);
        $responseString = curl_exec($ch);
        return Boss_Response::generate($responseString, $request->getParam('format'));
    
    }

}